import semantic.CSemanticAnalyzer
import lexis.{CLexemeType, CLexicalAnalyzer}
import scala.Some
import syntax._
import syntax.CGrammar
import utils.{CHTMLTree, CValuable, CFile}

object CMain extends App
{
    if (args.size != 3) println("Wrong number of arguments!")
    else
    {
        val lxms = CLexicalAnalyzer(CFile read args(0))

        val tree = CSyntacticAnalyzer(CGrammar.TERMINALS, CGrammar.NON_TERMINALS, CGrammar.START, CGrammar.PRIORITIES, lxms, CGrammar.Lexeme2Terminal)

        val code = CSemanticAnalyzer(tree)

        CFile.write(args(1), code)

        implicit object CValuableASTNode extends CValuable[CASTNode]
        {
            override def value(node:CASTNode) = node.category match
            {
                case _ => Some(node.value)
            }
        }

        CHTMLTree(tree, args(2) concat "tree.html")
    }
}
